package com.aaa.sbm.controller;

import com.aaa.sbm.entity.User;
import com.aaa.sbm.service.UserService;
import com.aaa.sbm.util.Result;
import com.aaa.sbm.common.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @FileName: UserController
 * @Description:
 * @Author: 王成林
 * @CreateTime: 2025/7/10 14:33
 * @Version: 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 获取用户列表
     */
    @GetMapping("list")
    public Result list(User user,
                      @RequestParam(defaultValue = "1") Integer pageNum,
                      @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("查询用户列表，参数：user={}, pageNum={}, pageSize={}", user, pageNum, pageSize);
        return userService.queryUserList(user, pageNum, pageSize);
    }

    @GetMapping("login")
    public Result login(String username, String password) {
        return userService.checkUser(username,password);
    }

    //退出 点击后 删除sesssion
    @PostMapping("logout")
    public Result logout() {
        return userService.logout();
    }

    // 用户注册
    @PostMapping("register")
    public Result register(@RequestBody User user) {
        log.info("收到注册请求，用户信息：{}", user);
        return userService.register(user);
    }
}
